Split array in the best possible way with multiple functions